package com.bckj.fastboot.upms.biz.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bckj.fastboot.upms.api.dto.UserAuthInfo;
import com.bckj.fastboot.upms.api.entity.SysUser;
import com.bckj.fastboot.upms.api.dto.SysUserQuery;
import com.bckj.fastboot.upms.api.vo.SysUserVO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.SelectProvider;
import org.apache.ibatis.jdbc.SQL;
import java.util.List;
import org.apache.ibatis.annotations.Mapper;

/**
 * 系统用户mapper
 *
 * @author wfc
 * @since 2023-06-03 22:42:05
 */
@Mapper
public interface SysUserMapper extends BaseMapper<SysUser> {

    /**
      * 列表
      */
    @SelectProvider(method = "list" , type = SysUserProvider.class)
    List<SysUserVO> list(SysUserQuery query);

    @Select("""
    select id,username,password,if(status=1,true,false) enabled,true accountNonExpired,true credentialsNonExpired,true accountNonLocked from sys_user where username=#{username} and delete_flag=0
    """)
    UserAuthInfo findByUsername(@Param("username") String username);

    class SysUserProvider{
        
        public String list(SysUserQuery query){
            return new SQL(){{
                SELECT("id, name, gender, username, create_time");
                FROM("sys_user");
                WHERE(" delete_flag = 0");
                where(this, query);
                ORDER_BY("id DESC");
            }}.toString();
        }

        public void where(SQL sql, SysUserQuery query) {

        }
    }
}

